import React from 'react';
import { Select, Spin } from 'antd';
import { connect } from 'dva';

const { Option } = Select;

@connect(({ publicdata: { sendOrderCustList }, loading }) => ({
  sendOrderCustList,
  loading: loading.effects['publicdata/fetchSendOrderCustList'],
}))
class Customer extends React.Component {
  // 获取地址
  search = value => {
    const { dispatch } = this.props;
    if (value.trim().length) {
      dispatch({
        type: 'publicdata/fetchSendOrderCustList',
        payload: { name: value.trim() },
      });
    }
  };

  render() {
    const { sendOrderCustList = [], loading, getData = () => {}, style } = this.props;
    return (
      <Select
        placeholder="请输入关键字检索"
        {...this.props}
        style={style || { width: '100%' }}
        showSearch
        optionFilterProp="children"
        showArrow={false}
        onSearch={this.search}
        onSelect={(value, options) => getData(value, options)}
        notFoundContent={loading ? <Spin size="small" /> : null}
        loading={false}
      >
        {sendOrderCustList.map(item => (
          <Option key={item.custId} optiopns={item}>
            {item.name}
          </Option>
        ))}
      </Select>
    );
  }
}
export default Customer;
